﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NHibernate;
using NHibernate.Cfg;

namespace Fruit.DAL
{
    public class SessionService
    {
        private ISessionFactory SessionFactory;
        public SessionService()
        {
            SessionFactory = GetSessionFactory();
        }
        /// <summary>
        /// 获取SessionFactory实例，用于创建Session
        /// </summary>
        /// <returns></returns>
        private ISessionFactory GetSessionFactory()
        {
            return (new Configuration()).Configure().BuildSessionFactory();
        }
        public ISession GetSession()
        {
            // 创建并打开一个Session
            return SessionFactory.OpenSession();
        }
    }
}
